package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;

/**
Author     :Dsi
Date       : 2021/11/30 17:35
Description: 调用者即将得到一个数据可的连接对象
*/
public class JDBUtils {

    public static Connection getDriver( String url,String user , String pwd) throws Exception{
        //获取驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //连接数据库
        Connection connection = DriverManager.getConnection(url,user,pwd);
        return connection;
    }
    public  static void close(Statement statement,Connection connection , PreparedStatement preparedStatement ){
        if(statement!=null){
            try{
               statement.close();
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                statement=null;
            }
        }
        if(connection!=null){
            try{
                connection.close();
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                connection=null;
            }
        }
        if(preparedStatement!=null){
            try{
                preparedStatement.close();
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                preparedStatement=null;
            }
        }
    }
}
